LEADTOOLS Barcode (Leadtools.Barcode assembly)

Save(String,BarcodeData[]) Method

Show in webframe
Example 







Name of the XML file to create
An array of BarcodeData objects to save.
Saves an array of BarcodeData objects to an XML file.
Syntax
public static void Save( 
   string fileName,
   BarcodeData[] data
)
'Declaration
 
Public Overloads Shared Sub Save( _
   ByVal fileName As String, _
   ByVal data() As BarcodeData _
) 
'Usage
 
Dim fileName As String
Dim data() As BarcodeData
 
BarcodeData.Save(fileName, data)
public static void Save( 
   string fileName,
   BarcodeData[] data
)

            

            
 function Leadtools.Barcode.BarcodeData.Save(String,BarcodeData[])( 
   fileName ,
   data 
)
public:
static void Save( 
   String^ fileName,
   array<BarcodeData^>^ data
) 

Parameters

fileName
Name of the XML file to create
data
An array of BarcodeData objects to save.
Remarks

The load/save methods are provided as helper methods for the user. The BarcodeEngine, BarcodeReader and BarcodeWriter do not use these methods internally.

data can be null (Nothing is Visual Basic). This is the equivalent of saving an empty array.

To load the data previously saved into an XML file, use BarcodeData.Load(string fileName).

To save and load data to an XML stream, use BarcodeData.Save(Stream stream, BarcodeData[] data) and BarcodeData.Load(Stream stream).

Example
Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Forms
Imports Leadtools.Barcode
Imports Leadtools.ImageProcessing

Public Sub BarcodeData_LoadSaveExample()
   Dim imageFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Barcode1.tif")
   Dim xmlFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "MyBarcodes.xml")

   ' Create a Barcode engine
   Dim engine As New BarcodeEngine()

   ' Load the image
   Using codecs As New RasterCodecs()
      Using image As RasterImage = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)
         ' Read all the barcodes
         Dim barcodes() As BarcodeData = engine.Reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, Nothing)

         ' Print out the barcodes we found
         Console.WriteLine("{0} barcodes found", barcodes.Length)
         For i As Integer = 0 To barcodes.Length - 1
            Dim barcode As BarcodeData = barcodes(i)
            Console.WriteLine("  {0} - {1} - {2}", i + 1, barcode.Symbology, barcode.Value)
         Next
         Console.WriteLine("-----------------")

         ' Save the barcodes to an XML file
         BarcodeData.Save(xmlFileName, barcodes)

         ' Now load the data back and print them out
         barcodes = BarcodeData.Load(xmlFileName)
         Console.WriteLine("{0} barcodes loaded", barcodes.Length)
         For i As Integer = 0 To barcodes.Length - 1
            Dim barcode As BarcodeData = barcodes(i)
            Console.WriteLine("  {0} - {1} - {2}", i + 1, barcode.Symbology, barcode.Value)
         Next
      End Using
   End Using
End Sub

Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Forms;
using Leadtools.Barcode;
using Leadtools.ImageProcessing;

public void BarcodeData_LoadSaveExample()
{
   string imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "Barcode1.tif");
   string xmlFileName = Path.Combine(LEAD_VARS.ImagesDir, "MyBarcodes.xml");

   // Create a Barcode engine
   BarcodeEngine engine = new BarcodeEngine();

   // Load the image
   using(RasterCodecs codecs = new RasterCodecs())
   {
      using(RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1))
      {
         // Read all the barcodes
         BarcodeData[] barcodes = engine.Reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, null);

         // Print out the barcodes we found
         Console.WriteLine("{0} barcodes found", barcodes.Length);
         for(int i = 0; i < barcodes.Length; i++)
         {
            BarcodeData barcode = barcodes[i];
            Console.WriteLine("  {0} - {1} - {2}", i + 1, barcode.Symbology, barcode.Value);
         }
         Console.WriteLine("-----------------");

         // Save the barcodes to an XML file
         BarcodeData.Save(xmlFileName, barcodes);

         // Now load the data back and print them out
         barcodes = BarcodeData.Load(xmlFileName);
         Console.WriteLine("{0} barcodes loaded", barcodes.Length);
         for(int i = 0; i < barcodes.Length; i++)
         {
            BarcodeData barcode = barcodes[i];
            Console.WriteLine("  {0} - {1} - {2}", i + 1, barcode.Symbology, barcode.Value);
         }
      }
   }
}

static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Barcode;
using Leadtools.ImageProcessing;

      
public async Task BarcodeData_LoadSaveExample()
{
   string imageFileName = @"Assets\Barcode1.tif";
   // Create a Barcode engine
   BarcodeEngine engine = new BarcodeEngine();

   // Load the image
   using(RasterCodecs codecs = new RasterCodecs())
   {
      StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(imageFileName);
      using(RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile)))
      {
         // Read all the barcodes
         BarcodeData[] barcodes = engine.Reader.ReadBarcodes(image, LeadRectHelper.Empty, 0, null);
         if (barcodes == null)
         {
            Debug.WriteLine("No barcodes found");
            return;
         }
         // Print out the barcodes we found
         Debug.WriteLine("{0} barcodes found", barcodes.Length);
         for(int i = 0; i < barcodes.Length; i++)
         {
            BarcodeData barcode = barcodes[i];
            Debug.WriteLine("  {0} - {1} - {2}", i + 1, barcode.Symbology, barcode.Value);
         }
         Debug.WriteLine("-----------------");
      }
   }
}
Requirements

Target Platforms

See Also

Reference

BarcodeData Class
BarcodeData Members
Overload List

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.

Leadtools.Barcode requires a Barcode Module license and unlock key. For more information, refer to: LEADTOOLS Toolkit Features